package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.constant.SystemConstant;
import com.atguigu.tingshu.common.login.TsLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.util.AuthContextHolder;
import com.atguigu.tingshu.model.user.UserInfo;
import com.atguigu.tingshu.model.user.VipServiceConfig;
import com.atguigu.tingshu.user.service.UserInfoService;
import com.atguigu.tingshu.vo.user.UserPaidRecordVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "用户管理接口")
@RestController
@RequestMapping("api/user/userInfo")
@SuppressWarnings({"all"})
public class UserInfoApiController {

	@Autowired
	private UserInfoService userInfoService;

	//供远程调用使用
	@GetMapping("/getUserInfo/{userId}")
	@Operation(summary = "获取用户信息")
	Result<UserInfo> getUserInfo(@PathVariable Long userId){
		UserInfo userInfo = userInfoService.getById(userId);
		return Result.ok(userInfo);
	}

	@Operation(summary = "获取用户购买的该专辑的声音信息与免费试听声音id")
	@PostMapping("/getPaidTrack/{albumId}")
	@TsLogin
	public Result<List<Long>> getPaidTrack(@PathVariable Long albumId, @RequestBody List<Long> allTrackIdList){
		Long userId = AuthContextHolder.getUserId();
		List<Long> paidTrackIdList = userInfoService.getPaidTrack(albumId,userId,allTrackIdList);
		return Result.ok(paidTrackIdList);
	}

	@Operation(summary = "判断用户是否购买了专辑")
	@GetMapping("/isPaidAlbum/{albumId}")
	@TsLogin
	public Result<Boolean> isPaidAlbum(@PathVariable Long albumId){
		Long userId = AuthContextHolder.getUserId();
		return Result.ok(userInfoService.isPaidAlbum(userId,albumId));
	}

	@PostMapping("/saveUserPaidRecord")
	@Operation(summary = "处理用户购买记录")
	Result<Boolean> saveUserPaidRecord(@RequestBody UserPaidRecordVo userPaidRecordVo){
		Boolean result = userInfoService.saveUserPaidRecord(userPaidRecordVo);
		return result ? Result.ok(result) : Result.fail(result);
	}
}

